package com.person.leetcode.editor.cn;

import java.util.ArrayList;

/**
 * 498.对角线遍历
 * 2022-06-14 11:41:18
 **/
public class Sequence_0498_DiagonalTraverse {
    public static void main(String[] args) {
        Solution solution = new Sequence_0498_DiagonalTraverse().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        //我讨厌矩阵模拟,纯纯浪费时间
        public int[] findDiagonalOrder(int[][] mat) {
            int rowNum = mat.length;//行数 i
            int colNum = mat[0].length;//列数 j
            int i = 0, j = 0;
            boolean topRig = true;//右上
            ArrayList<Integer> ans = new ArrayList<>();
            while (i < rowNum && j < colNum) {
                System.out.println();
                ans.add(mat[i][j]);
                if (topRig) {
                    if (j + 1 >= colNum) {
                        topRig = false;
                        i++;
                    } else if (i - 1 < 0) {
                        topRig = false;
                        j++;
                    }else{
                        j++;
                        i--;
                    }
                } else {
                    if (i + 1 >= rowNum) {
                        topRig = true;
                        j++;
                    } else if (j - 1 < 0) {
                        topRig = true;
                        i++;
                    }else{
                        i++;
                        j--;
                    }
                }
            }
            return ans.stream().mapToInt(Integer::valueOf).toArray();
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}